require 'thor'

module TerminalKeynote
  class CLI < Thor
    include Thor::Actions

    FILENAME = 'keynote.rb'

    desc 'new NAME', 'create new keynote'
    method_option :dir, desc: 'creating keynote file directory'
    def new(name)
      @name = name
      filedir = options[:dir] || Dir.pwd
      filepath = Pathname.new(filedir) + name + FILENAME

      create_keynote(filepath)
    end

    desc 'start', 'start keynote'
    method_option :dir, desc: 'keynote directory'
    def start
      filedir = options[:dir] || Dir.pwd
      filepath = Pathname.new(filedir) + FILENAME
      abort "#{filepath} is not exist :(" unless File.exist?(filepath)

      controller = KeynoteController.new
      keynote = Keynote.load(filepath)

      controller.start(keynote)
    end

    def self.source_root
      File.dirname(__FILE__)
    end

  private

    def create_keynote(filepath)
      template('templates/keynote.rb.erb', filepath)
    end
  end
end
